//
//  Person.m
//  OC02_实例变量可见度_方法
//
//  Created by 侯平章 on 16/2/21.
//  Copyright © 2016年 侯平章. All rights reserved.
//

#import "Person.h"

@implementation Person

#pragma mark -自定义初始化方法
- (instancetype)initWithName:(NSString*)name{
    self = [super init];
    if (self) {
        //实例变量赋值
      _name = name;
    }
    return self;
}

- (instancetype)initWithName:(NSString *)name sex:(NSString*)sex age:(NSInteger)age{
    self = [super init];
    if (self) {
        _name = name;
        _sex = sex;
        _age = age;
    }
    return self;
}

#pragma mark -重写init
- (instancetype)init{
    //1.调用父类的init方法. self 指对象本身
    self = [super init];
    //加一个判断,当self指针不为空时,在进行赋值
    if (self) {
        //2.给某个实例变量赋值
        _age = 20;
    }
    
    return self;
}

#pragma mark - other

- (void)sayHi{
    NSLog(@"%@,%@,%ld",_name,_sex,_age);
}

/** 需求:通过一个方法,把三个实例变量赋值.*/
- (void)name:(NSString*)name sex:(NSString*)sex age:(NSInteger)age{

    _name = name;
    _sex = sex;
    _age = age;
}

#pragma mark setter,getter方法.
/** setter,getter方法.*/
/** 需求:通过一个方法,对_name实例变量赋值*/
- (void)setName:(NSString*)name{
    _name = name;
}
/** 需求:通过一个方法,取出_name实例变量值*/
- (NSString*)name{
    return _name;
}

/** 构造器.*/
+ (instancetype)person{
//1. alloc,init
    Person *per = [[Person alloc] init];
//2.返回对象
    return per;

}

+ (instancetype)personWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
    Person *per = [[Person alloc] initWithName:name sex:sex age:age];
    return per;

}

@end
